<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		<title>班结管理</title>
		<script type="text/javascript" language="javascript" src="../script/card.js"></script>
		<script type="text/javascript" language="javascript" src="../script/common.js"></script>
		<script type="text/javascript" language="javascript" src="../script/common_stat.js"></script>
		<script language="javascript">
			var Page;

			function load(){
				Page = {};
				Eui.showNavigation();
				DWR.call(
					'counterService.openShift',
					Common.cOrg().id,
					Common.cOperator().id,
					fillShiftPage
					,{blockScreen:true}
				);
			}
			
			function fillShiftPage(result){
				//TX.Test.alertAll(result);
				$('confirmOpenBtn').disabled = true;
				$('prepareCloseBtn').disabled = true;
				$('confirmCloseBtn').disabled = true;
				$('shift').style.display = (result.current||result.last?'':'none')
				$('preShift').style.display = (result.newShift?'':'none');
				var shift;
				if (result.current){//存在已开班次
					shift = result.current;
					$('shiftTitle').innerHTML = '当前班次';
					TX.Shift.showDetail(shift,'shiftDetail');
					$('prepareCloseBtn').disabled = false;
					if (shift.prepareTime)
						$('confirmCloseBtn').disabled = false;
				}
				else{
					if(result.last){
						$('shiftTitle').innerHTML = '上次班结';
						TX.Shift.showDetail(result.last,'shiftDetail');
					}
					shift = result.newShift;
					if (shift.endTime){
						$('preshiftTitle').innerHTML = '待结班次 - 在以前的业务日期内有未结交易';
						$('confirmCloseBtn').disabled = false;
					}else if(shift.prepareTime){
						$('preshiftTitle').innerHTML = '准备开班 - 当前业务日期有未结交易';
						$('confirmOpenBtn').disabled = false;
						$('confirmCloseBtn').disabled = false;
					}else{
						$('preshiftTitle').innerHTML = '待开班次';
						$('confirmOpenBtn').disabled = false;
					}
					TX.Shift.showDetail(shift,'preshiftDetail');
				}
				Page.shiftID = shift.id;
				$('pivotView').style.display = shift.prepareTime?'':'none';
				$('lastShiftPivot').style.display = 'none';
				if(shift.prepareTime)
					TX.Shift.showShiftChecks(Page.shiftID);
				else if(result.last){
					$('lastShiftPivot').style.display = '';
					TX.Shift._showCardChecks({shiftId:result.last.id},'lastCard');
				}
			}
			
			function callCounterService(method){
				if(method == 'prepareCloseShift' || method == 'confirmCloseShift')//准备结班或确认结班
					SimulatePos.sendRequest();
					
				DWR.call(
					'counterService.'+method,
					Page.shiftID,
					fillShiftPage
					,{blockScreen:true}
				);
			}
		</script>
	</head>
	
	<body onload="load()">
		<div class="nav"><div id="nav">&nbsp;</div></div>
		
		<div id="shift" class="form" style="display:none" >
			<div class="formTitle"><span id="shiftTitle">上次班结</span></div>
			<div id="shiftDetail"></div>
		</div>
		
		<div id="preShift" class="form" style="display:none" >
			<div class="formTitle"><span id="preShiftTitle">待结班次</span></div>
			<div id="preShiftDetail"></div>
		</div>

		<div id="pivotView" class="form" style="display:none">
			<div id="pivotShift" class="formTitle" style="display:none">上次班结报表：</div>
			<div class="formTitle">卡库存统计报表</div>
			<div id="card"></div>
			<div class="formTitle">交易统计报表</div>
			<div id="trade"></div>
			<div class="formTitle">发票统计报表</div>
			<div id="invoice"></div>
		</div>
		
		<div id="lastShiftPivot" class="form" style="display:none">
			<div class="formTitle">上次班结卡片库存情况：</div>
			<div id="lastCard"></div>
		</div>
		
		<div>
			<button id="confirmOpenBtn" onclick="callCounterService('confirmOpenShift')" disabled>确认开班</button>
			<button id="prepareCloseBtn" onclick="callCounterService('prepareCloseShift')" disabled>准备结班</button>
			<button id="confirmCloseBtn" onclick="callCounterService('confirmCloseShift')" disabled>确认结班</button>
		</div>
	</body>
</html>